package JET.graphics;

import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import JET.Constants;
import JET.Centers.ControlCenter;
import JET.MouseStuff.MouseMode;
import JET.MouseStuff.MouseSubMode;
import java.awt.Component;

/**
 *
 * @author 057Ry
 */
public class GraphicPanelMouseWheelListener implements MouseWheelListener, Constants
{
    static final ControlCenter CC = ControlCenter.getInstance();
    private Component owner;
    private GraphicPanel gp;
    
    public GraphicPanelMouseWheelListener(Component owner) {
        this.owner = owner;
        this.gp = (GraphicPanel) owner;
    }
    
    public void mouseWheelMoved(MouseWheelEvent mwe) 
    {
        switch( CC.MC.getMouseOTFMode() )
        {
            case DO_NOTHING :
                if ( !(CC.MC.getMouseMode() == MouseMode.CREATE_CIRCLE && CC.MC.getMouseSubMode() == MouseSubMode.FIND_SECOND_OBJECT) &&
                     !(CC.MC.getMouseMode() == MouseMode.CREATE_SQUARENET && CC.MC.getMouseSubMode() == MouseSubMode.FIND_SECOND_OBJECT) )
                    scaleGraphicPanelView(mwe);
                    owner.repaint();
                break;
        }
        switch( CC.MC.getMouseMode() )
        {
            case CREATE_CIRCLE :
                switch( CC.MC.getMouseSubMode() )
                {
                    case FIND_SECOND_OBJECT :
                        CC.MC.mouseInteger += mwe.getWheelRotation();

                        if ( CC.MC.createCircleCenterPoint && CC.MC.createCircleDoubleSprings )
                            if( CC.MC.mouseInteger%2 != 0)
                                if( mwe.getWheelRotation()<0 ) CC.MC.mouseInteger--;
                                else if( mwe.getWheelRotation()>0 ) CC.MC.mouseInteger++;

                        if ( CC.MC.mouseInteger < 1 ) CC.MC.mouseInteger = 1;
                        owner.repaint();
                        break;
                }
                break;
                
            case CREATE_SQUARENET :
                switch( CC.MC.getMouseSubMode() )
                {
                    case FIND_SECOND_OBJECT :
                        CC.MC.mouseInteger += mwe.getWheelRotation();
                        if ( CC.MC.mouseInteger < 1 ) CC.MC.mouseInteger = 1;
                        owner.repaint();
                        break;
                }
                break;
        }
    }

    private void scaleGraphicPanelView(MouseWheelEvent mwe)
    {
        MouseEvent evt = CC.MC.mouseEvent;
        int steps = mwe.getWheelRotation();
        GraphicPanelHelper.scaleGraphicPanel(gp, steps, evt, mwe.isControlDown(), CC);
    }
}
